from spass.api.api_test import (test_assignment_version,
                                test_assignment_team,
                                test_assignment)
from optparse import OptionParser

def callback_test_assignment_version(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    test_assignment_version(parser.values.version[0], parser.values.version[1], parser.values.version[2], parser.values.version[3])

def callback_test_assignment_team(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    test_assignment_team(parser.values.team[0], parser.values.team[1], parser.values.team[2])

def callback_test_assignment(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    test_assignment(parser.values.assignment[0], parser.values.assignment[1])

def test(argv):
    parser = OptionParser()
    parser.set_usage("""spass test <options>""")
    parser.add_option("--assignment", action="callback", callback=callback_test_assignment, type="string", nargs=2, dest="assignment",
                      help="Tests the last assignment version of each team in the assignment. ARG : <assignment ID> <test name>")
    parser.add_option("--assignment-team", action="callback", callback=callback_test_assignment_team, type="string", nargs=3, dest="team",
                      help="Tests the last assignment version of a team in the assignment. ARG : <assignment ID> <team ID> <test name>")                      
    parser.add_option("--assignment-ver", action="callback", callback=callback_test_assignment_version, type="string", nargs=4, dest="version",
                      help="Tests an assignment version of a team in the assignment. ARG : <assignment ID> <team ID> <version ID> <test name>")    					  
    (options, args) = parser.parse_args(argv)
    return 0
